import render from 'src/hrpub/common/frame/render';
import { createPage, base } from 'nc-lightapp-front';
/* 公共组件 */
import Pagination from 'src/hrpub/common/components/Pagination/index';
import Layout from 'src/hrpub/basicsetting/infosetmgt/components/layout';
/* htmls */
import HRBack from 'src/hrpub/common/components/hr-back/index';
import ReferSearch from 'src/hrpub/common/components/referSearch/org';
import EmptyData from 'src/hrpub/common/components/emptyImg';
/* 公共css */
// import 'src/hrpub/common/static/fonts/iconfont.css';
/* actions */
import headerAction from '../actions/header';
import initAction from '../actions/main';
import cardAction from '../actions/card';
import paginationAction from '../actions/paginationaction';
/* custom style */
import './index.less';
import { __assign } from 'tslib';
const { Header, Main } = Layout;
const { Content } = Main;
const { NCTabs } = base;
const { NCTabPane } = NCTabs;
const Homepage = render({
	actions: {
		initAction,
		headerAction,
		cardAction,
		paginationAction
	}
})(({ props, action, state }) => {
	const { transEntry, button, editTable, search, form, cardPagination, cardTable } = props;
	const { lang, hrorgobj, showMode, pageInfo, hasListData, tabIndex } = transEntry;
	let H = action.initAction.getHeight();
	let hasPkOrg = JSON.stringify(hrorgobj) === '{}' ? false : true;
	let topClassName = 'nc-bill-card';
	return (
		<Layout className={topClassName}>
			<Header className="nc-bill-header-area">
				<div className="tools">
					<Choose>
						<When condition={showMode === 'list-browse'}>
							<ReferSearch
								orgVal={hrorgobj}
								getOrgData={action.headerAction.searchChange}
								showEmpty={transEntry.widget?true:false}
								queryCondition={() => {
									return {
										controlType: 1
									};
								}}
							/>
							{hasPkOrg &&
								button.createButtonApp({
									area: 'list-header',
									onButtonClick: action.headerAction.openFilterModal,
									popContainer: document.querySelector('.tools')
								})}
						</When>
						<When condition={showMode !== 'list-browse'}>
							<HRBack className="header-button-area" onClick={action.headerAction.backToList} />
							<div className="buttons header-button-area">
								<Choose>
									{/* && !widget */}
									<When condition={showMode === 'card-edit'}>
										{button.createButtonApp({
											area: 'card-header',
											onButtonClick: action.headerAction.approve,
											popContainer: document.querySelector('.tools')
										})}
									</When>
									<When condition={showMode === 'card-browse' && tabIndex === '2'}>
										<div className="header-cardPagination-area">
											{cardPagination.createCardPagination({
												handlePageInfoChange: action.headerAction.handlePageInfoChange
											})}
										</div>
									</When>
								</Choose>
							</div>
						</When>
					</Choose>
				</div>
			</Header>
			<Main>
				<Content>
					<div>
						<Choose>
							<When condition={showMode === 'list-browse'}>
								<div className="list-view nc-bill-table-area">
									<If condition={hasPkOrg || transEntry.widget}>
										<div className="tab-definInfo-area">
												<NCTabs
													defaultActiveKey={transEntry.tabIndex}
													onChange={action.initAction.tabChange}
												>
													<NCTabPane tab={lang['gx6008-000085']} key="1" />
													<If condition = {!transEntry.widget}>
														<NCTabPane tab={lang['gx6008-000086']} key="2" />
													</If>
												</NCTabs>
										</div>
										{editTable.createEditTable('handovergrid', {
											height: H,
											onRowDoubleClick: action.initAction.doubleClick,
											cancelCustomRightMenu: true
										})}
										<Pagination
											{...pageInfo}
											hideOnSinglePage={!hasListData}
											showQuickJumper={true}
											showSizeChanger={true}
											onChange={action.paginationAction.changePageNum}
											onShowSizeChange={action.paginationAction.changePageSize}
										/>
									</If>
									<If condition={!hasPkOrg && !transEntry.widget}>
										<EmptyData text={lang['gx6008-000084']} height={H} />
									</If>
								</div>
							</When>
							<When condition={showMode !== 'list-browse' && hasPkOrg}>
								<div className="card-view nc-bill-form-area">
									{[
										form.createForm('psninfoheadform'),
										cardTable.createCardTable('handoverdetailmygrid', {
											hideSwitch: () => {
												return false;
											},
											cancelCustomRightMenu: true
										}),
										cardTable.createCardTable('handoverdetailgrid', {
											hideSwitch: () => {
												return false;
											},
											cancelCustomRightMenu: true
										})
									]}
								</div>
							</When>
						</Choose>
					</div>
				</Content>
				{/* 查询modal */}
				<div style={{ display: 'none' }}>
					{search.NCCreateSearch('searchform', {
						clickSearchBtn: action.initAction.toSearch
					})}
				</div>
			</Main>
		</Layout>
	);
});

export default createPage({})(Homepage);
